# -*- coding: utf-8 -*-
from sqlite3 import dbapi2 as sqlite3

# configuration
DATABASE = 'teampupshoppers.db'

def connect_db():
    """Returns a new connection to the database."""
    return sqlite3.connect(DATABASE)


def init_db():
    try:
        con = connect_db()
        def read_data():
            f = open('schema.sql','r')
            with f:
                data = f.read()
                return data 
            
        with con:
            cur = con.cursor()
            sql = read_data()
            cur.executescript(sql)
         
    except sqlite3.Error, e:
        if con:
            con.rollback()
    finally:
        if con:
            con.close()    
    
if __name__ == '__main__':
    init_db()